<template>
    <div>

        <h1>科室信息显示</h1>
        <a href="/addks">添加科室</a>
        <br>
        <a href="/showys">医生信息</a> 
        <br>
         <a href="/">病房信息</a>
         <br>
         <a href="https://localhost:7125/api/Depart/DaochuShowxlk">科室信息导出</a>
        <br>
        科室名称:
        <input type="text" placeholder="科室名称" v-model="page.name">
        科室人数:
        <input v-model="page.m1" type="number" placeholder="科室最少人数">
        -
        <input v-model="page.m2" type="number" placeholder="科室最多人数">
        <input type="button" value="查询" @click="chax">
        <input type="button" value="重置" @click="cz">
        <table class="table">
            <thead>
                <tr>
                    <td>科室编号</td>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室简介</td>
                    <td>创建日期</td>
                    <td>删除</td>
                    <td>修改</td>
                </tr>
            </thead>
            <tbody>
                 <tr v-for="e in data">
                    <td>{{ e.id }}</td>
                    <td>{{ e.departName }}</td>
                    <td>{{ e.departNum }}</td>
                    <td>{{ e.departMS }}</td>
                    <td>{{ moment(e.departDate).format("YYYY-MM-DD") }}</td>
                    <td><input type="button" value="删除" @click="deletehouse(e.id)"></td>
                    <td><input type="button" value="修改" @click="updatehouse(e.id)"></td>

                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import moment from 'moment';
import { useRouter } from 'vue-router'

const router=useRouter();
onMounted(()=>{
    show();
})
const chax=()=>{
    show();
}
//修改页
const updatehouse=(val:any)=>{
  router.push({path:"/upks",query:{id:val}})
}

//删除
const deletehouse=(val:any)=>{
    if(!confirm("确认删除吗"))
{
    return;
}
  axios.delete("/api/Depart/DeleteKS",{params:{id:val}}).then(res=>{
     if(res.data>0)
     {
        alert("删除成功");
        show();
     }
     else{
        alert("删除失败")
        return;
     }
  })
}

const data =ref([{
    "id": 1,
    "departName": "内科",
    "departNum": 6,
    "departMS": "内科是我院重要的临床室之一",
    "departDate": "2025-05-13T20:09:36.8493297",
    "isDeleted": false
  }])

  const cz=()=>{
    page.value.name="";
    page.value.m1=0;
    page.value.m2=0
  }

  const page =ref({
    name:"",
    m1:0,
    m2:0,
  })

const show =()=>{
    axios.get("/api/Depart/ShowKS",{params:page.value}).then(res=>{
        data.value=res.data
    })
}

</script>

<style scoped>

</style>    